﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArbolandiaBL
{
    internal class UICategory
    {
        private ArbolandiaDBDataContext _db;

        public UICategory()
        {
            _db = new ArbolandiaDBDataContext();
        }

        internal List<UICategoryResume> GetCategorys()
        {
            var result = new List<UICategoryResume>();
            var query = from sp in _db.spGetCategorys()
                        select new UICategoryResume
                        {
                            Id = sp.Id,
                            ImageUrl = sp.ImageUrl,
                            MetaDescription = sp.MetaKeywords,
                            Name = sp.Name,
                            Subcategory = new List<UISubcategoryResume>()
                        };
            foreach (var item in query)
            {
                result.Add(item);
            }
            //var query = from p in _db.Product_Category
            //            select new UICategoryResume()
            //            {
            //                Id = p.Id,
            //                MetaDescription = p.MetaKeywords,
            //                Name = p.Name,
            //                Subcategory = new List<UISubcategoryResume>()
            //            };
            //result.AddRange(query.ToList());
            //foreach (var cat in result)
            //{
            //    var qq = CompiledQuerys.GetSubCategory(_db, cat.Id);
            //    //var querySub = CompiledQuerys.GetSubCategory(_db, cat.Id);
            //    //if (querySub.Count() > 0) { cat.Subcategory.AddRange(querySub.ToList()); }
            //}

            return result;

        }

        internal List<UIProductsHome> GetOfertasDestacadosHome()
        {
            return CompiledQuerys.GetOfertasDestacadosHome(_db);
        }

        internal List<UIProductsHome> GetOfertasByCategoria(int idCategory)
        {
            return CompiledQuerys.GetOfertasByCategoria(_db, idCategory);
        }


    }
}
